package dao

import (
	"context"
	"gorm.io/gorm"
)

type RewardDao interface {
	CreateReward(ctx context.Context, rmd Reward) (int64, error)
	GetReward(ctx context.Context, rid int64) (Reward, error)
	UpdateStatus(ctx context.Context, rid int64, status uint8) error
}
type GormReward struct {
	db *gorm.DB
}

func (g GormReward) CreateReward(ctx context.Context, rmd Reward) (int64, error) {
	err := g.db.WithContext(ctx).Create(&rmd).Error
	return rmd.Id, err
}
func (g GormReward) GetReward(ctx context.Context, rid int64) (Reward, error) {
	var r Reward
	err := g.db.WithContext(ctx).Where("id=?", rid).First(&r).Error
	return r, err
}
func (g GormReward) UpdateStatus(ctx context.Context, rid int64, status uint8) error {
	return g.db.WithContext(ctx).Model(&Reward{}).Where("biz_id=?", rid).Updates(map[string]any{
		"status": status,
	}).Error
}
func NewGormGormReward(db *gorm.DB) RewardDao {
	return &GormReward{db: db}
}
